# ui/base_widget.py
import logging
from PySide6.QtWidgets import QMessageBox
from PySide6.QtCore import QCoreApplication

# 配置日志记录
logging.basicConfig(level=logging.ERROR, format='%(asctime)s - %(levelname)s - %(message)s')

class BaseWidgetMixin:
    """所有UI组件的Mixin类，提供统一的样式和功能"""

    # 统一的样式表
    UNIFIED_STYLESHEET = """
        QWidget {
            font-family: "Microsoft YaHei", "SimHei", sans-serif;
        }
        QLabel {
            color: #333;
        }
        QPushButton {
            background-color: #4CAF50;
            color: white;
            border: none;
            padding: 5px 10px;
            border-radius: 3px;
        }
        QPushButton:hover {
            background-color: #45a049;
        }
        QPushButton:pressed {
            background-color: #3d8b40;
        }
        QLineEdit {
            border: 1px solid #ccc;
            border-radius: 3px;
            padding: 5px;
        }
        QTableView {
            gridline-color: #eee;
        }
    """

    def setup_ui(self):
        """初始化UI组件"""
        pass

    def setup_connections(self):
        """连接信号和槽"""
        pass

    def setup_styles(self):
        """设置统一的样式"""
        try:
            self.setStyleSheet(self.UNIFIED_STYLESHEET)
        except Exception as e:
            logging.error(f"设置样式表失败: {str(e)}")

    def show_error(self, message):
        """显示错误消息"""
        QMessageBox.critical(self, QCoreApplication.translate("BaseWidgetMixin", "错误"), message)

    def show_info(self, message):
        """显示信息消息"""
        QMessageBox.information(self, QCoreApplication.translate("BaseWidgetMixin", "提示"), message)

    def show_warning(self, message):
        """显示警告消息"""
        QMessageBox.warning(self, QCoreApplication.translate("BaseWidgetMixin", "警告"), message)